/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.tom.social.dal.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Tom
 */
@Entity
@Table(name = "Site_SiteLink")
@NamedQueries({
	@NamedQuery(name = "SiteSiteLink.findAll", query = "SELECT s FROM SiteSiteLink s"),
	@NamedQuery(name = "SiteSiteLink.findAllBetween", query = "SELECT s FROM SiteSiteLink s WHERE s.added BETWEEN :start AND :end"),
	@NamedQuery(name = "SiteSiteLink.findBySiteId", query = "SELECT s FROM SiteSiteLink s WHERE s.siteSiteLinkPK.siteId = :siteId"),
	@NamedQuery(name = "SiteSiteLink.countBySiteId", query = "SELECT COUNT(s) FROM SiteSiteLink s WHERE s.siteSiteLinkPK.siteId = :siteId"),
	@NamedQuery(name = "SiteSiteLink.findBySiteLink", query = "SELECT s FROM SiteSiteLink s WHERE s.siteSiteLinkPK.siteLinkId = :siteLinkId"),
	@NamedQuery(name = "SiteSiteLink.findBySiteIdAndSiteLinkId", query = "SELECT s FROM SiteSiteLink s WHERE s.siteSiteLinkPK.siteId = :siteId AND s.siteSiteLinkPK.siteLinkId = :siteLinkId"),
	@NamedQuery(name = "SiteSiteLink.findByUrlAndSiteId", query = "SELECT sl FROM SiteSiteLink s JOIN s.siteLink sl WHERE s.siteSiteLinkPK.siteId = :siteId AND sl.url = :url"),
	@NamedQuery(name = "SiteSiteLink.getUrlsBySite", query = "SELECT sl.url FROM SiteSiteLink s JOIN s.siteLink sl WHERE s.siteSiteLinkPK.siteId = :siteId"),
	@NamedQuery(name = "SiteSiteLink.findByAdded", query = "SELECT s FROM SiteSiteLink s WHERE s.added = :added"),
	@NamedQuery(name = "SiteSiteLink.findNewest", query = "SELECT s FROM SiteSiteLink s WHERE s.added = :added ORDER BY s.added DESC")})
public class SiteSiteLink implements Serializable {
	private static final long serialVersionUID = 1L;
	@EmbeddedId
	protected SiteSiteLinkPK siteSiteLinkPK;
	@Basic(optional = false)
    @Column(name = "added")
    @Temporal(TemporalType.TIMESTAMP)
	private Date added;
	@Basic(optional = false)
    @Column(name = "count")
	private int count;
	@JoinColumn(name = "site_id", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
	private Site site;
	@JoinColumn(name = "siteLink_id", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
	private SiteLink siteLink;

	public SiteSiteLink() {
	}

	public SiteSiteLink(int siteId, int siteLinkid) {
		this(siteId, siteLinkid, new Date(), 1);
	}

	public SiteSiteLink(int siteId, int siteLinkid, Date added, int count) {
		this.siteSiteLinkPK = new SiteSiteLinkPK(siteId, siteLinkid);
		this.added = added;
		this.count = count;
	}

	public SiteSiteLinkPK getSiteSiteLinkPK() {
		return siteSiteLinkPK;
	}

	public void setSiteSiteLinkPK(SiteSiteLinkPK siteSiteLinkPK) {
		this.siteSiteLinkPK = siteSiteLinkPK;
	}

	public Date getAdded() {
		return added;
	}

	public void setAdded(Date added) {
		this.added = added;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public Site getSite() {
		return site;
	}

	public void setSite(Site site) {
		this.site = site;
	}

	public SiteLink getSiteLink() {
		return siteLink;
	}

	public void setSiteLink(SiteLink siteLink) {
		this.siteLink = siteLink;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (siteSiteLinkPK != null ? siteSiteLinkPK.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof SiteSiteLink)) {
			return false;
		}
		SiteSiteLink other = (SiteSiteLink) object;
		if ((this.siteSiteLinkPK == null && other.siteSiteLinkPK != null) || (this.siteSiteLinkPK != null && !this.siteSiteLinkPK.equals(other.siteSiteLinkPK))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "pl.tom.social.dal.entity.SiteSiteLink[siteSiteLinkPK=" + siteSiteLinkPK + "]";
	}

}
